/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.axiom.persistence;

import com.axiom.vo.student_course;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

/**
 *
 * @author Shuhail
 */
public class student_course_persist {
    
        Session sess = null;
        Transaction tx = null;
    
    public static student_course_persist getInstance() {
        
        return new student_course_persist();
    }

    public student_course_persist() {
    
        SessionFactory sf = new Configuration().configure().buildSessionFactory();
        sess = sf.openSession();
        tx = sess.beginTransaction();
    }
    
    
    public boolean insertFresh(student_course studCourse) {
        
        try {
            
            sess.save(studCourse);
            tx.commit();
        }
        catch(Exception e) {
            
            return false;
        }
        return true;
    }
    
    
    public int deleteStudent(String studId) {
        
        Query query = sess.getNamedQuery("deleteStudentCourse");
        query.setParameter("stud_id", studId);
        try {
            
            int delRows = query.executeUpdate();
            tx.commit();
            return delRows;
            
        }
        catch(Exception e) {
            
            return 0;
        }
    }
    public static void main(String[] args) {
        
        student_course sc = new student_course();
        sc.setStudent_id("S1");
        sc.setCourse_id("C1");
        new student_course_persist().deleteStudent("S24");
    }
    
    
    
    
    
    
}
